// 定义分數类
class Score {
    score = 0;
    level = 1;
    scoreElement: HTMLElement | null;
    levelElement: HTMLElement | null;
    maxLevel: number;
    levelUpScore: number;

    constructor(maxLevel: number = 10, levelUpScore: number = 10) {
        this.scoreElement = document.getElementById('score');
        this.levelElement = document.getElementById('level');
        this.maxLevel = maxLevel;
        this.levelUpScore = levelUpScore;
    }

    // 分数添加
    addScore() {
        this.score++;
        this!.scoreElement!.innerHTML = this.score + '';

        if (this.score % this.levelUpScore === 0) {
            this.levelUp();
        }
    }

    // 等级提升
    levelUp() {
        if (this.level < this.maxLevel) {
            this.level++;
            this.levelElement!.innerHTML = this.level + '';
        }
    }
}

export default Score;
